<?php defined('SYSPATH') OR die('No direct access allowed.');

// Dies ist der Basis-Controller er Applikation.  
class Base_Controller extends Template_Controller{
	 
	public $template='template';
	public $modelname='';
	public $controllername='';
	public $parent_column='parent_id';
	public $session;
	public $auth;
	public $user;
	
	public function __construct()
	{ 	  
		parent::__construct();
		
		$this->session=new Session();
		$this->auth=new Auth();
		
		$this->session->set('last_controller', $this->controllername);	
		$this->lastview=array('','','','');
		$this->settings=ORM::factory('setting')->get_array();
		
		if(array_key_exists('lang', $this->settings)==true){
			if($this->session->get('lang')=='' ){
				$this->session->set('lang', 'de');
			}
		}else{
			$this->session->set('lang','de');
		}
		
		define('IMGPATH', 'mediaadmin/img/');
		define('CONTDIR', 'ext/');
		define('LANG', $this->session->get('lang'));
		
		$this->template->title='Sigi Admin';
		$this->template->content="No Content on this site";
		$this->template->pagesmenu='';
		$this->template->collectionmenu='';
		$this->template->navileft='Das Menu';
		$this->profiler=new Profiler();
		$this->profiler->disable();
		
		//$this->template->debug= $this->profiler->render(TRUE);	
		
	}
	
	public function __initmenu(){
		$navileft=new View('mainnavi');	
		$this->lastview=$this->session->get('lastview_array');	
		
		if(isset($this->lastview[2])){
			if($this->lastview[2]=='page'){	
				$pagesmenu=new View('page/menu');
				$pagesmenu->pages=ORM::factory('page')->orderby('position')->find_all();					
				$page=ORM::factory('page',isset($this->lastview[4])?$this->lastview[4]:NULL);
				$pagesmenu->openones=$page->get_openones();
				$navileft->pagesmenu=$pagesmenu;
			}
			
			if($this->lastview[2]=='collection'){
				$collectionmenu=new View('collection/menu');
				$collectionmenu->collections=ORM::factory('collection')->orderby('title')->find_all();
				$navileft->collectionmenu=$collectionmenu;
			}
		}
		
		$this->template->navileft=$navileft;
			
	}
	
	public function set_session_var($var, $value=NULL){
		$this->session->set($var, $value);
		url::redirect($this->session->get('lastview'));
	}
	

}
